package uit.minito.views;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import uit.minito.timduongxebuyt.StaticVariables;
import android.content.Context;
import android.util.DisplayMetrics;

public class MyUtilities {
	public static String convertURL(String str) {

	    String url = null;
	    try{
	    url = new String(str.trim().replace("|", "%7C").replace(" ", "%20"));
	    }catch(Exception e){
	        e.printStackTrace();
	    }
	    return url;
	}
	public static String removeDotZeroFromDouble(double _value){
		String valueString=String.valueOf(_value);
		String finalValueString=valueString;
		if(valueString.contains(".")){
			int dotIndex=valueString.indexOf(".");
			finalValueString=valueString.substring(0, dotIndex);
		}
		return finalValueString;
	}
	public static int convertRouterNameToInt(String routerName){
		int result=0;
		String onlyNumberString=routerName.replace(StaticVariables.ROUTER_PREFIX, "");
		result=Integer.valueOf(onlyNumberString);
		return result;
	}
	public static ArrayList<Integer> convertRouterNameArrayToIntArray(ArrayList<String> routerNameList){
		ArrayList<Integer> listInt=new ArrayList<Integer>();
		for(int i=0;i<routerNameList.size();i++){
			String iName=routerNameList.get(i);
			int iNameInt=convertRouterNameToInt(iName);
			listInt.add(iNameInt);
		}
		return listInt;
	}
	public static double roundDouble(double value,int numberOfDecimal){
		String formatString="#.";  
		for(int i=0;i<numberOfDecimal;i++){
			formatString+="#";
		}
		DecimalFormat twoDForm = new DecimalFormat(formatString);
		String formatDoubleString=twoDForm.format(value);
	    return Double.valueOf(formatDoubleString);
	}
	public static String parseDate(Date dateTime){

		 SimpleDateFormat iso8601Format = new SimpleDateFormat(
         "yyyy-MM-dd HH:mm:ss");
		 String result;
		 result=iso8601Format.format(dateTime);
		 return result;
	}
	public static Date parseString(String dateString){
		SimpleDateFormat iso8601Format = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
		Date result=null;
		try {
			result = (Date) iso8601Format.parse(dateString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	public static String makeBoldAndBiggerText(String text){
		return "<b><big>"+text+"</big></b>";
	}
	public static String makeColorToText(String text,String colorText){
		return "<font color='"+colorText+"'>"+text+"</font>";
	}
	public static int convertToDP(double _pixel,Context context){
		DisplayMetrics metrics = context.getResources().getDisplayMetrics();
		int pixels = (int) (metrics.density * _pixel);
		return pixels;
	}
}
